import { Cache } from "../../cache/Cache";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { GameMapUtil } from "../../scene/map/GameMapUtil";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SGuildUnion } from "../../../../Message/Public/SGuildUnion";
type int = number;
//class RobCityUtill
    
    export  class RobCityUtill
    {
        

        public static isMyGuild(arg1: int, arg2: int, arg3: int): Boolean
        {
            var loc1=0;
            if (Cache.instance.guildUnion.hasUnion) 
            {
                loc1 = Cache.instance.guildUnion.myGuildUnionInfo.firstGuildInfo.guildId;
            }
            else 
            {
                loc1 = Cache.instance.role.entityInfo.guildId;
            }
            if (loc1 > 0) 
            {
                return EntityUtil.isSameServerByProxyAndServer(arg1, arg2) && loc1 == arg3;
            }
            return false;
        }

        public static isMyGuildByEntityId(arg1: SEntityId): Boolean
        {
            var loc1=0;
            if (Cache.instance.guildUnion.hasUnion) 
            {
                loc1 = Cache.instance.guildUnion.myGuildUnionInfo.firstGuildInfo.guildId;
            }
            else 
            {
                loc1 = Cache.instance.role.entityInfo.guildId;
            }
            if (loc1 > 0) 
            {
                return EntityUtil.isSameServerByRole(arg1) && loc1 == arg1.id;
            }
            return false;
        }

        public static getForceName(arg1: int, arg2: Boolean=true, arg3: Boolean=true, arg4: Boolean=true): string
        {
            if (GameMapUtil.curMapState.isRobCityCopyTwo) 
            {
                return RobCityUtill.getCopyTwoForceName(arg1, arg2, arg3, arg4);
            }
            if (GameMapUtil.curMapState.isRobCityCopyThree) 
            {
                return RobCityUtill.getCopyThreeForceName(arg1, arg2, arg3, arg4);
            }
            return "";
        }

        public static getForceColor(arg1: int, arg2: Boolean)
        {
            if (GameMapUtil.curMapState.isRobCityCopyTwo) 
            {
                return RobCityUtill.getCopyTwoForceColor(arg1, arg2);
            }
            if (GameMapUtil.curMapState.isRobCityCopyThree) 
            {
                return RobCityUtill.getCopyThreeForceColor(arg1, arg2);
            }
            return arg2 ? 16711680 : "#ff0000";
        }

        /* internal  */static getCopyTwoForceName(arg1: int, arg2: Boolean, arg3: Boolean, arg4: Boolean): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1;
            if ((loc1 = Cache.instance.robCity.robCityCopyTwoInfo) && loc1.robCityTwoJoinTeams && loc1.robCityTwoJoinTeams.length > 0) 
            {
                loc2 = "";
                var loc6=0;
                var loc7=loc1.robCityTwoJoinTeams;
                for(loc3 of loc7) 
                {
                    if (loc3.froce != arg1) 
                    {
                        continue;
                    }
                    loc4 = "";
                    if (RobCityUtill.checkHasUnion(loc3.guildUnion) && arg4) 
                    {
                        loc4 = Language.getString(60882);
                    }
                    loc5 = "";
                    if (arg2) 
                    {
                        loc5 = "[" + EntityUtil.getProxyName(loc3.sEntityId) + "]" + loc3.guildName + loc4;
                    }
                    else 
                    {
                        loc5 = loc3.guildName + loc4;
                    }
                    if (arg3) 
                    {
                        loc2 = RobCityUtill.getCopyTwoForceColor(loc3.froce, false);
                        return HTMLUtil.addColor(loc5, loc2);
                    }
                    return loc5;
                }
            }
            return "";
        }

        /* internal  */static getCopyTwoForceColor(arg1: int, arg2: Boolean)
        {
            if (arg1 == Cache.instance.role.entityInfo.force) 
            {
                return arg2 ? GlobalStyle.color5Uint : GlobalStyle.color5;
            }
            return arg2 ? GlobalStyle.color7Uint : GlobalStyle.color7;
        }

        /* internal  */static getCopyThreeForceName(arg1: int, arg2: Boolean, arg3: Boolean, arg4: Boolean): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1;
            if ((loc1 = Cache.instance.robCity.robCityCopyThreeInfo) && loc1.robCityThreeJoinTeams && loc1.robCityThreeJoinTeams.length > 0) 
            {
                loc2 = "";
                var loc6=0;
                var loc7=loc1.robCityThreeJoinTeams;
                for(loc3 of loc7) 
                {
                    if (loc3.froce != arg1) 
                    {
                        continue;
                    }
                    loc4 = "";
                    if (RobCityUtill.checkHasUnion(loc3.guildUnion) && arg4) 
                    {
                        loc4 = Language.getString(60882);
                    }
                    loc5 = "";
                    if (arg2) 
                    {
                        loc5 = "[" + EntityUtil.getProxyName(loc3.sEntityId) + "]" + loc3.guildName + loc4;
                    }
                    else 
                    {
                        loc5 = loc3.guildName + loc4;
                    }
                    if (arg3) 
                    {
                        loc2 = RobCityUtill.getCopyTwoForceColor(loc3.froce, false);
                        return HTMLUtil.addColor(loc5, loc2);
                    }
                    return loc5;
                }
            }
            return "";
        }

        /* internal  */static getCopyThreeForceColor(arg1: int, arg2: Boolean)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (arg1 == Cache.instance.role.entityInfo.force) 
            {
                return arg2 ? GlobalStyle.color5Uint : GlobalStyle.color5;
            }
            loc1 = Cache.instance.robCity.robCityCopyThreeInfo;
            if (loc1 && loc1.robCityThreeJoinTeams && loc1.robCityThreeJoinTeams.length > 0) 
            {
                loc2 = "";
                var loc4=0;
                var loc5=loc1.robCityThreeJoinTeams;
                for(loc3 of loc5) 
                {
                    if (loc3.froce != arg1) 
                    {
                        continue;
                    }
                    if (loc3.shaBak > 0) 
                    {
                        return arg2 ? GlobalStyle.color7Uint : GlobalStyle.color7;
                        continue;
                    }
                    return arg2 ? GlobalStyle.color6Uint : GlobalStyle.color6;
                }
            }
            return arg2 ? GlobalStyle.color7Uint : GlobalStyle.color7;
        }

        public static checkHasUnion(arg1: SGuildUnion): Boolean
        {
            if (arg1) 
            {
                if (arg1.secondGuildId > 0 || arg1.thirdGuildId > 0) 
                {
                    return true;
                }
            }
            return false;
        }
    }
